<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"
	xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="search-form" autocomplete="off">
					<div class="select-list">
						<ul>
							<li>组名 ：<input type="text" name="groupName" />
							</li>
							<li>同步表 ：<input type="text" name="tabName" />
							</li>
							<li>目标表 ：<input type="text" name="targetName" />
							</li>

							<li><a class="btn btn-primary btn-rounded btn-sm"
								onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm"
								onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>

			<div class="btn-group-sm hidden-xs" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="quartz:wisDataGroup:add">
					<i class="fa fa-plus"></i>添加
				</a> 
				<a class="btn btn-primary btn-edit " onclick="importExcel();" shiro:hasPermission="quartz:wisDataGroup:add"> 
					<i class="fa fa-file-excel-o"></i>导入
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="quartz:wisDataGroup:edit"> 
					<i class="fa fa-edit"></i>修改
				</a> 
				<a class="btn btn-primary btn-edit " onclick="$.table.exportExcel('search-form')" shiro:hasPermission="quartz:wisDataGroup:add"> 
					<i class="fa fa-file-o"></i>导出
				</a>
				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="quartz:wisDataGroup:remove"> 
					<i class="fa fa-remove"></i> 删除
				</a>
			</div>

			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>

		</div>
	</div>
	<div th:include="include :: footer"></div>
	<script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('quartz:wisDataGroup:edit')}]];
        var removeFlag = [[${@permission.hasPermi('quartz:wisDataGroup:remove')}]];
        var prefix = ctx + "quartz/wisDataGroup";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "数据同步组",
                columns: [{
		            checkbox: true
		        },
				{
					field : 'id', 
					title : '主键',
					visible : false
				},
				{
					field : 'groupName', 
					title : '同步组组名' 
				},
				{
					field : 'sourceaId', 
					title : '同步数据源ID',
					visible : false
				},
				{
					field : 'sourceaName', 
					title : '同步数据源名称' 
				},
				{
					field : 'sourcebId', 
					title : '目标数据源ID' ,
					visible : false
				},
				{
					field : 'sourcebName', 
					title : '目标数据源名称' 
				},
				{
					field : 'tabName', 
					title : '同步表名称' 
				},
				{
					field : 'targetName', 
					title : '目标表名称' 
				},
				{
					field : 'createBy', 
					title : '创建人' 
				},
				{
					field : 'createTime', 
					title : '创建时间' 
				},
				{
					field : 'updateBy', 
					title : '修改人' 
				},
				{
					field : 'updateTime', 
					title : '修改时间' 
				},
				{
					field : 'sync_way', 
					title : '同步组状态' ,
				 	formatter: function(value, row, index) {
		            	var result = '同步表数据写入目标表';
		            	if(value == 1) {
		            		result = '目标表数据写入同步表' ;
		            	}
		            	if(value == 2) {
		            		result = '双向写入' ;
		            	}
						return result ;
		            }
				},
				{
					field : 'state', 
					title : '同步组状态' ,
				 	formatter: function(value, row, index) {
		            	var result = '停用';
		            	if(value == 1) {
		            		result = '启用' ;
		            	}
						return result ;
		            }
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
		            	actions.push('<a class="btn btn-primary btn-xs" href="#" onclick="LinkColumn(\'' + row.id + '\')"><i class="fa fa-link"></i>字段关联</a> ');
		            	if(row.state == 1) {
		            		actions.push('<a class="btn btn-primary btn-xs" href="#" onclick="ExeSyncData(\'' + row.id + '\')"><i class="fa fa-refresh"></i>执行</a> ');
		            	}
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });
        
        function importExcel() {
        	$.modal.open('数据同步组导入', prefix + "/importExcel", 800, 320);
        }
        
        function LinkColumn(id) {
        	var url = prefix + "/editWidthCol/"+id ;
			createMenuItem(url, "同步对接字段关联管理");
        }
        
        function ExeSyncData(id) {
        	$.modal.confirm("确定同步数据吗？", function() {
        		$.modal.loading("正在处理中，请稍后...");
        		var url = ctx + 'quartz/wisDataCol/exeSync?id='+id ;
            	var config = {
        	        url: url,
        	        type: 'post',
        	        dataType: 'json',
        	        data: {},
        	        success: function(result) {
        	        	$.modal.msgSuccess('同步成功...........');
        	        	$.modal.closeLoading() ;
        	        	$.modal.refreshTab() ;
        	        }
        	    };
        	    $.ajax(config)
        	})
        }
        
    </script>
</body>
</html>